<template>
  <div>
    <el-card class="box-card">
      <el-tabs stretch  v-model="activeName" @tab-click="handleClick" >
        <el-tab-pane label="密码登录" name="first">
          <el-form :model="ruleForm" ref="ruleForm" label-width="60px" class="demo-ruleForm">
            <el-form-item label="用户名">
              <el-input v-model="ruleForm.username" placeholder="请输入用户名"></el-input>
            </el-form-item>
            <el-form-item label="密码">
              <el-input v-model="ruleForm.password" placeholder="请输入密码" show-password></el-input>
            </el-form-item>
            <el-form>
              <el-button :plain="true" type="primary" @click="submitForm('ruleForm')">登录</el-button>
            </el-form>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="微信登陆" name="second">
<!--          <el-image :src="require()"></el-image>-->
          <img src="../assets/imgs/2.png" alt=""/>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeName: 'first',
      ruleForm:{
        username: 'root',
        password: '123456'
      }
    }
  },
  methods: {
    submitForm(formName) {
          let url = 'http://localhost:9580/users/login';
          console.log('url = ' + url);

          let formData = this.qs.stringify(this.ruleForm);
          console.log('formData = ' + formData);

          this.axios.post(url, formData).then((response) => {
            let responseBody = response.data;
            console.log(responseBody);
            if (responseBody.state == 20000) {
              this.$message({
                showClose: true,
                message: '登录成功！',
                type: 'success'
              });
              let jwt = responseBody.data;
              console.log('jwt = ' + jwt);
              localStorage.setItem('jwt', jwt);
              console.log('已经将JWT存入到localStorage中，即将跳转页面……');
              this.$router.push('/');
            } else {
              this.$message({
                showClose: true,
                message: responseBody.message,
                type: 'error'
              });
            }
          });
    },
    handleClick(tab, event) {
      console.log(tab, event);
    }
  }
}
</script>

<style>
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}

.box-card {
  width: 450px;
  margin: 250px auto;
  text-align: center;
}

.el-input {
  /*width: 360px;*/
  margin-bottom: 20px;
}

</style>